package com.zhejiangzhengyuan.municipal_common.utils.waterRuler;

/** 异或计算工具类 */
public class BCCUtils {

  public static String getBCC(String content) {
    content = change(content);
    String[] b = content.split(" ");
    int a = 0;
    for (String s : b) {
      a ^= Integer.parseInt(s, 16);
    }
    if (a < 10) {
      return "0" + a;
    }
    return Integer.toHexString(a);
  }

  public static String change(String content) {
    StringBuilder str = new StringBuilder();
    for (int i = 0; i < content.length(); i++) {
      if (i % 2 == 0) {
        str.append(" ").append(content, i, i + 1);
      } else {
        str.append(content, i, i + 1);
      }
    }
    return str.toString().trim();
  }
}
